﻿using Abp.Application.Features;
using Abp.Authorization;
using Abp.Localization;
using Abp.MultiTenancy;
using Mt.Site.Core.Authorization;
using Mt.Site.Core.Base.Authorization;
using Mt.Site.Core.ContentManagement.Features;
using System.Collections.Generic;

namespace Mt.Site.Core.ContentManagement.Permissions
{
    public class ContentPermissionProvider : AuthorizationProvider
    {
        public const string ModuleName = "App.Module.Content";
        public const string ModuleName2 = "App.Module.Content2";

        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            var contentFeature = new SimpleFeatureDependency(true, ContentFeatures.ContentFeature);

            var pages = context.GetPermissionOrNull(AppPermissions.Pages) ?? context.CreatePermission(AppPermissions.Pages, L("Pages"));
            var newsManage = pages.CreateChildMtMenuPermission2(
                ContentPermissions.Pages_Manage_Content,
                new List<string> { ModuleName, ModuleName2 },
                false, L("Content"), multiTenancySides: MultiTenancySides.Tenant, featureDependency: contentFeature);
            newsManage.CreateChildMtMenuPermission2(
                ContentPermissions.Pages_Manage_Content_Create,
                new List<string> { ModuleName, ModuleName2 },
                false, L("CreatingContent"), multiTenancySides: MultiTenancySides.Tenant, featureDependency: contentFeature);
            newsManage.CreateChildMtMenuPermission2(
                ContentPermissions.Pages_Manage_Content_Update,
                new List<string> { ModuleName, ModuleName2 },
                false, L("EditingContent"), multiTenancySides: MultiTenancySides.Tenant, featureDependency: contentFeature);
            newsManage.CreateChildMtMenuPermission2(
                ContentPermissions.Pages_Manage_Content_Delete,
                new List<string> { ModuleName, ModuleName2 },
                false, L("DeletingContent"), multiTenancySides: MultiTenancySides.Tenant, featureDependency: contentFeature);
            newsManage.CreateChildMtMenuPermission2(
                ContentPermissions.Pages_Manage_Content_Query,
                new List<string> { ModuleName, ModuleName2 },
                false, L("QueryContent"), multiTenancySides: MultiTenancySides.Tenant, featureDependency: contentFeature);
            newsManage.CreateChildMtMenuPermission2(
                ContentPermissions.Pages_Manage_Content_Publish,
                new List<string> { ModuleName, ModuleName2 },
                false, L("QueryPublish"), multiTenancySides: MultiTenancySides.Tenant, featureDependency: contentFeature);
            newsManage.CreateChildMtMenuPermission2(
                ContentPermissions.Pages_Manage_Content_Synchorization,
                new List<string> { ModuleName, ModuleName2 },
                false, L("Synchorization"), multiTenancySides: MultiTenancySides.Tenant, featureDependency: contentFeature);

            newsManage.CreateChildMtMenuPermission2(
                ContentPermissions.Pages_Manage_Content_Preview,
                new List<string> { ModuleName, ModuleName2 },
                false, L("Synchorization"), multiTenancySides: MultiTenancySides.Tenant, featureDependency: contentFeature);
        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, MtSiteConsts.LocalizationSourceName_Permissions);
        }
    }
}
